from PySide6.QtWidgets import QApplication, QSizePolicy, QPushButton, QWidget, QGridLayout
import sys

class CustomWidget(QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.setWindowTitle('QLabel and  QLineEdit')

        btn_1 = QPushButton("One")
        btn_2 = QPushButton("Two")
        btn_3 = QPushButton("Three")
        btn_4 = QPushButton("Four")
        btn_5 = QPushButton("Five")
        btn_6 = QPushButton("Six")
        btn_7 = QPushButton("Seven")

        # P.S. 因为 默认的延展策略垂直方向不延展，所以如果不改变延展策略最终的结果有点怪，所以配置垂直方向要延展的按键的延展策略
        btn_3.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        grid_layout = QGridLayout()
        grid_layout.addWidget(btn_1, 0, 0)  # 按坐标填充，（0，0）
        grid_layout.addWidget(btn_2, 0, 1, 1, 2)    # 最后两个参数表示合并单元格：一行两列，1 row 2 column
        grid_layout.addWidget(btn_3, 1, 0, 2, 1)    # 以(1, 0)点为开始，合并 2 行 1 列
        grid_layout.addWidget(btn_4, 1, 1)
        grid_layout.addWidget(btn_5, 1, 2)
        grid_layout.addWidget(btn_6, 2, 1)
        grid_layout.addWidget(btn_7, 2, 2)

        self.setLayout(grid_layout)

app = QApplication(sys.argv)

window = CustomWidget()
window.show()

app.exec()
